<?php

namespace app\common\service\pay\alipay;

use app\common\model\Alipay;
use app\common\service\pay\Base;
use app\common\service\pay\PayInterface;
use app\model\Config;
use app\model\PayLog;
use think\facade\Db;
use think\facade\Request;
use Yansongda\Pay\Pay;

class AliPayWap extends AliPayBase implements PayInterface
{


    public $pay_channel = PayLog::PAY_CHANNEL_ALIPAY;

    public $trade_type = 'ALIWAP';

    public $config;


    public function pay()
    {

        $return_url = input('redirect_url', '/index.php/api/');

        if (!strstr($return_url,'http')){
            $return_url = Request::domain() . $return_url;
        }

        $host = env('app.api_url');
        $return_url = $host . '/api/v2.wechat/authRedirect?url=' . urlencode($return_url);


//        $return_url = 'https://ymhuichong.kuaizhan.com/#/order/index?type=3';

        $notify_url = Request::domain() . '/index.php/api/notifyV3/alipayNotify';

        $pay = new Alipay(0, $notify_url);


        if (isLocal()) {
            $sale_price = 1;

        } else {
            $sale_price = $this->sale_price;
        }

        return $pay->wap([
            'name' => $this->title,
            'out_trade_no' => $this->payLog->out_no,
            'total_amount' => $sale_price, //分
            'return_url' => $return_url
        ]);

    }


}